﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.IO;
public class EffectManager : Singleton<EffectManager>
{
    Dictionary<string, XmlNode> xmlEffects = new Dictionary<string, XmlNode>();
    public string XmlPath;
    public void InitFormXml() 
    {
       this.XmlPath = Game.ConfigPath + "Effects.xml";
       string strEffect = File.ReadAllText(XmlPath);
       XmlDocument doc = new XmlDocument();
       doc.LoadXml(strEffect);
       XmlNode node = doc.ChildNodes[0];
       for (int i = 0; i < node.ChildNodes.Count; i++)
       {
          string effectName =  node.ChildNodes[i].Attributes["Name"].Value;
          this.xmlEffects[effectName] = node.ChildNodes[i];
       }
    }

    public XmlNode GetEffect(string effectName) 
    {
      return xmlEffects[effectName];
    }

    public EffectGeneric CreateEffect(string effectName,Unit unit) 
    {
        EffectGeneric Effect = null;
        XmlNode effectNode = EffectManager.Instance.GetEffect(effectName);
        Effect = (EffectGeneric)System.Activator.CreateInstance(System.Type.GetType(effectNode.Name));
        Effect.Init(effectNode,unit);
        return Effect;
    }

}
